﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Meqs.Entity;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class ClassHistoryLogic : CommonLogic<ClassHistory, int>, IClassHistoryLogic
    {
        #region Implementation of ICommonLogic<ClassHistory, int>

        /// <sammury>
        /// 创建对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(ClassHistory entity)
        {
            //return CreateObject(entity);
            InsertCustomer("ClassHistory.Insert", entity);
            return 0;
        }

        /// <sammury>
        /// 更新对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(ClassHistory entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public ClassHistory FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<ClassHistory> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public int Delete(int entityId, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("RID", entityId);
            ht.Add("SchoolMark", schoolMark);
            return DeleteCustomer("ClassHistory.Delete", ht);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll(string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            return DeleteCustomer("ClassHistory.Delete", ht);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public ClassHistory FindById(int entityId, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("RID", entityId);
            ht.Add("SchoolMark", schoolMark);
            return FindCustomerByID<ClassHistory>("ClassHistory.FindById", ht);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public int FindCount(string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            return FindCustomerByCount("ClassHistory.FindCount", ht);
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public IList<ClassHistory> FindAll(string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            return FindCustomer<ClassHistory>("ClassHistory.Find", ht);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<ClassHistory> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        public int DeleteByClassID(int clsID, String schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("ClassID", clsID);
            ht.Add("SchoolMark", schoolMark);
            return DeleteCustomer("ClassHistory.DelByClsID", ht);
        }
        public int UpdateOneClassStuinfo(int clsID,  int year, int term)
        {
            string statementName = "ClassHistory.UpdateOneClassStuinfo";
            Hashtable ht = new Hashtable();
            ht.Add("ClassID", clsID);
            ht.Add("SchoolYear", year);
            ht.Add("Term", term);
            ht.Add("ISEFFECT", 0);
            return ExecuteUpdate(statementName, ht);
        }
        /// <summary>
        /// 查找指定学年的有效班级
        /// </summary>
        public IList<ClsInfo> FindClassesInSchoolYear(int schoolYear, String schoolMark, int? grade)
        { 
            Hashtable ht = new Hashtable();
            ht.Add("SchoolYear", schoolYear);
            ht.Add("SchoolMark", schoolMark);
            if(grade != null)
                ht.Add("Grade", grade);

            return FindCustomer<ClsInfo>("ClassHistory.FindClassesInSchoolYear", ht);
        }

        /// <summary>
        /// 查找指定学年的有效班级
        /// </summary>
        public IList<VClsInfo> FindClassesInSchoolYearToView(int schoolYear, String schoolMark, int? grade)
        { 
            Hashtable ht = new Hashtable();
            ht.Add("SchoolYear", schoolYear);
            ht.Add("SchoolMark", schoolMark);
            if(grade != null)
                ht.Add("Grade", grade);

            return FindCustomer<VClsInfo>("ClassHistory.FindClassesInSchoolYearToView", ht);
        }

        public IList<ClassHistory> FindClassHistory(int schoolYear, int clsID, String schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolYear", schoolYear);
            ht.Add("SchoolMark", schoolMark);
            ht.Add("ClsID", clsID);

            return FindCustomer<ClassHistory>("ClassHistory.FindClassHistory", ht);
        }
    }
}
